//
//  stats_server_processor.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2013-2014 Razvan Coca (razvan dot coca at  gmail dot com)
// This is mostly generated code. Generator is distributed under GPL. Edit it to suit your needs.
// 


#ifndef STATS_SERVER_PROCESSOR_HPP
#define STATS_SERVER_PROCESSOR_HPP
#include <string>
#include <boost/logic/tribool_fwd.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include "stats_server/stats.pb.h"
#include "components/defs/util_types.hpp"
#include "components/utils/stats_container.hpp"
#include "stats_server/stats.pb.h"
namespace components{
namespace protocol{

class stats_server_processor
{
public:
     enum states{start, reply};
private:
    stats_container stats_container_;

    std::vector<stats_message_t> pending_replies_;
    std::vector<stats_message_t>::iterator current_replies_;
    states current_state_;
    std::string cluster_;
    std::string node_;
    u_int32_t trans_id_;
    u_int32_t seq_no_;
    void update_source(stats_message_t& msg);
    void update_trans(stats_message_t& msg);
    void init_trans(stats_message_t& msg);
    void reset_pending_replies();
public:
    bool shutdown() { return stats_container_.shutdown();}
    stats_server_processor(boost::asio::io_service& ios,std::string const& persist_path,boost::posix_time::minutes lifetime,std::string cluster, std::string node);
    boost::logic::tribool process_request_set(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);
    boost::logic::tribool process_request_get(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);
    boost::logic::tribool process_do_reply(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);
    boost::logic::tribool process_end(stats_message_t& msg,udp_endpoint_t& peer,boost::system::error_code const &ec);

};
}// end namespace protocol
}// end namespace components
#endif // STATS_SERVER_PROCESSOR_HPP
